package v1

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"go-mall/model"
	"go-mall/pkg/util"
	"go-mall/service"
	"net/http"
)

func CreateOrder(c *gin.Context) {
	claims, _ := util.ParseToken(c.GetHeader("Authorization"))
	var createOrder service.OrderService
	var requestBody *model.RequestBody
	if err := c.ShouldBindJSON(&requestBody); err == nil {
		res := createOrder.Create(c.Request.Context(), requestBody, claims.ID)
		c.JSON(http.StatusOK, res)
	} else {
		fmt.Println("Error", err)
		c.JSON(http.StatusBadRequest, err)
	}
}

func ListOrder(c *gin.Context) {
	claims, _ := util.ParseToken(c.GetHeader("Authorization"))
	var listOrder service.OrderService
	if err := c.ShouldBind(&listOrder); err == nil {
		res := listOrder.List(c.Request.Context(), claims.ID)
		c.JSON(http.StatusOK, res)
	} else {
		fmt.Println("Error", err)
		c.JSON(http.StatusBadRequest, err)
	}
}

func ShowOrder(c *gin.Context) {
	//claims, _ := util.ParseToken(c.GetHeader("Authorization"))
	//var showOrderService service.OrderService
	//if err := c.ShouldBind(&showOrderService); err == nil {
	//	res := showOrderService.Show(c.Request.Context(), claims.ID, c.Param("id"))
	//	c.JSON(http.StatusOK, res)
	//} else {
	//	fmt.Println("Error", err)
	//	c.JSON(http.StatusBadRequest, err)
	//}
}
